<template>
  <div>
    <a-form-model ref="form" :model="model" style="max-width: 600px; margin: 40px auto 0;" :rules="validatorRules">
      <a-form-model-item label="排班方案" :labelCol="labelCol" :wrapperCol="wrapperCol" required prop="planId">
        <a-input v-model="model.planName" readonly/>
      </a-form-model-item>
      <a-form-model-item label="排班科室" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="departId">
        <a-input v-model="model.departmentName" readonly/>
      </a-form-model-item>

      <a-table
        ref='table'
        size='middle'
        bordered
        rowKey='id'
        :columns='columns'
        :dataSource='dataSource'
        :pagination='ipagination'
        :loading='loading'
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change='handleTableChange'>

        <span slot='action' slot-scope='text, record'>
           <a-popconfirm title='确定删除吗?' @confirm='() => handleDelete(record.id)' v-if='record.status==0'>
                          <a>取消参与</a>
                        </a-popconfirm>
        </span>

      </a-table>
      <a-form-item :wrapperCol="{span: 19, offset: 5}">
        <a-button type="primary" @click="nextStep">下一步</a-button>
      </a-form-item>
    </a-form-model>
  </div>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import CommonRuleParams from '@views/his/scheduling/RuleForm/CommonSchedulingRuleParams'
import { httpAction, getAction, postAction } from '@/api/manage'
import pick from 'lodash.pick'
import { queryMyDepartTreeList } from '@api/api'
import moment from 'moment'

export default {
  name: 'RuleStep1',
  mixins: [JeecgListMixin],
  components: {
    CommonRuleParams
  },
  data() {
    return {
      form: this.$form.createForm(this),
      model: {

      },
      rangeDateTime: [],
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      selectedRowKeys: [],
      validatorRules: {
        name: [{ required: true, message: '请填写此次排班名称!' }],
        planId: [{ required: true, message: '请选择班次方案!' }]
      },
      disableMixinCreated:true,
      confirmLoading: false,
      // 表头
      columns: [
        {
          title: '姓名',
          align: 'center',
          dataIndex: 'name'
        },
        {
          title: '职称',
          align: 'center',
          dataIndex: 'title',
        },
      ],
      url: {
        list: '/store/employee/list',
        get: '/his/scheduling/get',
        edit: '/his/activity'
      }
    }
  },
  created() {
    console.log(' -- RuleStep1 created -- ')
    this.$nextTick(() => {
      Object.assign(this.model, CommonRuleParams.commonRuleForm1Data.dataSource)
      this.form.setFieldsValue(pick(this.model, 'storeInfoId'))
    })
    const id = this.$route.query.id
    getAction(this.url.get,{id:id}).then((res) => {
      this.model=res.result;
    })
    this.loadData();
  },
  methods: {
    moment,

    nextStep() {
      let that = this
      // 触发表单验证
      this.form.validateFields((err, values) => {
        if (!err) {
          let formData = Object.assign(this.model, values)
          console.log('commonRuleForm1Data formData >>>', formData)
          this.$confirm({
            title: "确认提交",
            content: "是否确认生成排班表?",
            onOk: function () {
              postAction('/his/scheduling/allowAdd',{"departId":that.model.departId,"id":that.model.id,"eyIds":that.selectedRowKeys}).then((res) => {
                if(res.success){
                  formData.schedulingCode=res.result;
                  Object.assign(CommonRuleParams.commonRuleForm1Data.dataSource, formData)
                  that.$emit('nextStep')
                }else{
                  that.$message.warn(res.message)
                }
              })
            }
          });
        }
      })
    }

  }
}
</script>

<style lang="less" scoped>
.stepFormText {
  margin-bottom: 24px;

  .ant-form-item-label,
  .ant-form-item-control {
    line-height: 22px;
  }
}

</style>